package com.toman.ui.work.base;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.CardView;
import android.util.Log;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.toman.Interfaces.NewBaseUrl;
import com.toman.JavaBean.RemindingRecordEntity;
import com.toman.R;
import com.toman.Util.ToastUtil;
import com.toman.Util.ViewUtil;
import com.toman.toolbar.ToolBarActivity;
import com.lzy.okhttputils.OkHttpUtils;
import com.lzy.okhttputils.callback.StringCallback;

import butterknife.BindView;
import butterknife.ButterKnife;
import okhttp3.Request;
import okhttp3.Response;

public class RemindInfActivity extends ToolBarActivity {

    String id;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.tv_title2)
    TextView tvTitle2;

    @BindView(R.id.tv_title4)
    TextView tvTitle4;
    @BindView(R.id.tv_title5)
    TextView tvTitle5;
    @BindView(R.id.cv_base)
    CardView cvBase;
    @BindView(R.id.tv_content1)
    TextView tvContent1;
    @BindView(R.id.tv_content2)
    TextView tvContent2;
    @BindView(R.id.cv_more)
    CardView cvMore;
    @BindView(R.id.tv_title6)
    TextView tvTitle6;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_remind_inf);
        ButterKnife.bind(this);
        initToolBar("提醒作业详情");
        initView();
        get();
    }

    private void initView() {
        id = getIntent().getStringExtra("id");
        ToastUtil.print(id);

    }

    public void get() {
        OkHttpUtils
                .get(NewBaseUrl.remind_info_get + id)
                .params("token", token)
                .params("id", id)
                .execute(new StringCallback() {
                    @Override
                    public void onResponse(boolean isFromCache, String result, Request request, @Nullable Response response) {
                        Log.i("test", "提醒作业: " + result);

                        JSONObject jsonObj = JSON.parseObject(result);
                        int code = jsonObj.getInteger("code");ViewUtil.lagout(code,getApplicationContext());
                        if (code == 0) {
                            RemindingRecordEntity bean = (RemindingRecordEntity) JSON.parseObject(jsonObj.getString("remindingRecord"), RemindingRecordEntity.class);
                            tvTitle.setText(bean.getEventTitle());
                            tvTitle2.setText(bean.getEventCode());
//                            tvTitle3.setText();
                            tvTitle4.setText(bean.getNotifyWayName());
                            tvTitle5.setText(bean.getNotifyTime());
                            tvTitle6.setText(bean.getNotifyRateName());
                            tvContent2.setText(bean.getEvent());
                            tvContent1.setText(bean.getNotifyUserRealNames());

//                            tvTitleNo.setText(bean.getTerminalCode());


                        } else {
                            ToastUtil.error(getApplicationContext(), jsonObj.getString("msg"));
                        }

                    }
                });
    }
}
